/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: UserController
 * Author:   kadibeieun
 * Date:     2019/8/8 9:37
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.mengde.controller;


import com.mengde.common.ResultEnum;
import com.mengde.common.vo.ResultVO;
import com.mengde.entity.SyUser;
import com.mengde.service.SelfUserDetailsService;
import com.mengde.service.SyUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author kadibeieun
 * @create 2019/8/8
 * @since 1.0.0
 */
@RestController
@RequestMapping("test")
@Slf4j
public class UserController {
    @Autowired
    private SyUserService syUserService;
    @Autowired
    private SelfUserDetailsService userDetailsService;

    @Autowired
    private PasswordEncoder bCryptPasswordEncoder;

    @RequestMapping("/getUser")
    public List<SyUser> getUser(){

        List<SyUser> result = syUserService.getUser();
        log.info("获取内容", result);
        return result;
    }

    @PostMapping("/register")
    public Map<String, Object> register(String username, String password){

        String encode = bCryptPasswordEncoder.encode(password);
        userDetailsService.register(username,encode);
        return ResultVO.result(ResultEnum.SUCCESS,true);
    }



}